package com.exam.vo;

import com.exam.vo.examEnum.ResultCode;

public class ResultData<T> {
    //请求码
    private int code;
    //操作结果信息，默认为code对应的msg
    private String msg;
    //存取数据
    private T data;

    public ResultData() {
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMsg();
    }


    public static ResultData error(int code, String msg) {
        ResultData<Object> result = new ResultData<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
    public static ResultData success(Object data) {
        ResultData<Object> result = new ResultData<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

    public ResultData(T data) {
        this();
        this.data = data;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
